<template>
  <div class="page-wraper">
    <el-row> 打开时间：{{ new Date() }} </el-row>
    <el-row>
      <el-button type="primary" size="small" @click="getDocId"
        >getDocId</el-button
      >
      <el-button type="primary" size="small" @click="getDocInfo"
        >getDocInfo</el-button
      >
    </el-row>
    <el-row>
      <el-button type="primary" size="small" @click="getParagraphSize"
        >getParagraphSize</el-button
      >
      <el-button type="primary" size="small" @click="getParagraphs"
        >getParagraphs</el-button
      >
    </el-row>
    <el-row>
      <el-input-number
        v-model="pIndex"
        controls="false"
        size="small"
        :min="0"
        label="start"
      ></el-input-number>
      <el-button type="primary" size="small" @click="getParagraph"
        >getParagraph</el-button
      >
      <el-button type="primary" size="small" @click="getParagraphStyle"
        >getParagraphStyle</el-button
      >
      <el-button type="primary" size="small" @click="setParagraphStyle"
        >setParagraphStyle</el-button
      >
    </el-row>
    <el-row>
      <el-input-number
        v-model="start"
        controls="false"
        size="small"
        :min="0"
        label="start"
      ></el-input-number>
      <el-input-number
        v-model="end"
        controls="false"
        size="small"
        :min="0"
        label="end"
      ></el-input-number>
      <el-button type="primary" size="small" @click="selectRange"
        >selectRange</el-button
      >
      <el-button type="primary" size="small" @click="getRangeText"
        >getRangeText</el-button
      >
      <el-input
        v-model="text"
        placeholder="替换文本"
        type="textarea"
      ></el-input>
      <el-button type="primary" size="small" @click="replaceRangeText"
        >replaceRangeText</el-button
      >
      <el-button type="primary" size="small" @click="getRangeFont"
        >getRangeFont</el-button
      >
      <el-button type="primary" size="small" @click="setRangeFont"
        >setRangeFont</el-button
      >
      <el-button type="primary" size="small" @click="getNowRange"
        >getNowRange</el-button
      >
    </el-row>
    <el-row>
      <el-button type="primary" size="small" @click="openWord"
        >openWord</el-button
      >
      <el-button type="primary" size="small" @click="insertWord"
        >insertWord</el-button
      >
    </el-row>
    <el-row>
      <el-button type="primary" size="small" @click="getBookmarks"
        >getBookmarks</el-button
      >
      <el-input v-model="bName" placeholder="书签名称"></el-input>
      <el-button type="primary" size="small" @click="getBookmark"
        >getBookmark</el-button
      >
      <el-input-number
        v-model="bStart"
        controls="false"
        size="small"
        :min="0"
        label="start"
      ></el-input-number>
      <el-input-number
        v-model="bEnd"
        controls="false"
        size="small"
        :min="0"
        label="end"
      ></el-input-number>
      <el-button type="primary" size="small" @click="createBookmark"
        >createBookmark</el-button
      >
      <el-button type="primary" size="small" @click="removeBookmarks"
        >removeBookmarks</el-button
      >
      <el-button type="primary" size="small" @click="removeBookmark"
        >removeBookmark</el-button
      >
    </el-row>
    <el-row>
      <el-input v-model="token" placeholder="token"></el-input>
      <el-button type="primary" size="small" @click="writeToken"
        >writeToken</el-button
      >
      <el-button type="primary" size="small" @click="removeToken"
        >removeToken</el-button
      >
    </el-row>
    <el-row>
      <el-button type="primary" size="small" @click="openLoginForm"
        >openLoginForm</el-button
      >
    </el-row>
    <el-row>
      <el-button type="primary" size="small" @click="closeLoginForm"
        >closeLoginForm</el-button
      >
    </el-row>
    <el-row>
      <el-button type="primary" size="small" @click="request"
        >request</el-button
      >
    </el-row>
  </div>
</template>

<script>
export default {
  data() {
    return {
      pIndex: 0,
      start: 0,
      end: 1,
      text: '',
      token: '',
      bName: '',
      bStart: 0,
      bEnd: 1,
    }
  },
  methods: {
    getDocId() {
      alert(window.c_methods.getDocId())
    },
    getDocInfo() {
      alert(window.c_methods.getDocInfo())
    },
    getParagraphSize() {
      alert(window.c_methods.getParagraphSize())
    },
    getParagraph() {
      alert(window.c_methods.getParagraph(this.pIndex))
    },
    getParagraphStyle() {
      alert(window.c_methods.getParagraphStyle(this.pIndex))
    },
    setParagraphStyle() {
      window.c_methods.setParagraphStyle(this.pIndex, {
        alignment: 0,
        lineSpacing: 18.0,
        lineSpacingRule: 1,
        spaceBefore: 7.8,
        spaceAfter: 15.6,
        leftIndent: 10.5,
        rightIndent: 21.0,
        firstLineIndent: 30,
      })
    },
    getParagraphs() {
      alert(window.c_methods.getParagraphs())
    },
    selectRange() {
      window.c_methods.selectRange(this.start, this.end)
    },
    getRangeText() {
      alert(window.c_methods.getRangeText(this.start, this.end))
    },
    replaceRangeText() {
      window.c_methods.replaceRangeText(this.start, this.end, this.text)
    },
    getRangeFont() {
      alert(window.c_methods.getRangeFont(this.start, this.end))
    },
    setRangeFont() {
      window.c_methods.setRangeFont(this.start, this.end, {
        name: '楷体',
        size: 30,
        bold: -1,
        italic: -1,
        color: [111, 133, 166],
      })
    },
    getNowRange() {
      alert(window.c_methods.getNowRange())
    },
    openWord() {
      let url =
        'https://gyshuzhi.oss-cn-hangzhou.aliyuncs.com/template/1721296830341.doc'
      // let url = "http://pcccenter-hz.oss-cn-hangzhou.aliyuncs.com/internal-files-share/1/2024/11/07/1730946167846.pdf";
      alert(window.c_methods.openWord(url))
    },
    insertWord() {
      window.c_methods.insertWord(
        this.start,
        this.end,
        'https://gyshuzhi.oss-cn-hangzhou.aliyuncs.com/template/1721296830341.doc'
      )
    },
    getBookmarks() {
      alert(window.c_methods.getBookmarks())
    },
    removeBookmarks() {
      alert(window.c_methods.removeBookmarks())
    },
    getBookmark() {
      alert(window.c_methods.getBookmark(this.bName))
    },
    removeBookmark() {
      alert(window.c_methods.removeBookmark(this.bName))
    },
    createBookmark() {
      alert(window.c_methods.createBookmark(this.bName, this.bStart, this.bEnd))
    },
    writeToken() {
      window.c_methods.writeToken(this.token)
      window.localStorage.setItem(
        'LoginInfo',
        JSON.stringify({
          usercode: '22f949f7-3b4d-4a64-a590-5286078de867',
          compid: '1',
          username: '陈雄',
        })
      )
      window.localStorage.setItem('token', this.token)
    },
    removeToken() {
      window.c_methods.removeToken()
    },
    openLoginForm() {
      window.c_methods.openLoginForm()
    },
    closeLoginForm() {
      window.c_methods.closeLoginForm()
    },
    request() {
      var xhr = new XMLHttpRequest()
      xhr.open(
        'POST',
        'http://idw-service-error-patrol.ag.dacube.cn/article/getByIds',
        true
      ) // 替换为你的 URL
      xhr.setRequestHeader('Content-Type', 'application/json')
      xhr.setRequestHeader('Connection', 'keep-alive')
      xhr.setRequestHeader('Cache-Control', 'no-cache')
      xhr.setRequestHeader('X-Custom-Header', 'token')
      xhr.setRequestHeader('token', '888')
      xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
          if (xhr.status >= 200 && xhr.status < 300) {
            window.alert(xhr.responseText)
          } else {
            window.alert('请求失败：' + JSON.stringify(xhr))
          }
        }
      }
      xhr.send(
        JSON.stringify({
          ids: [
            'd3e32c09b8e66b1762da0172c48f3fc5',
            '11a90cb5bb4899e0533a20d834992198',
            '346328c79e348b0177cd850585ed098d',
          ],
          qualifier: ['id', 'title'],
        })
      )
    },
  },
}
</script>

<style scoped>
.el-row {
  margin-bottom: 20px;
}
</style>
